package middleware

import (
	"github.com/labstack/echo"
)

func AuthMiddleware() echo.HandlerFunc {
	// return func(c *gin.Context) {
	// 	err := auth.TokenValid(c.Request)
	// 	if err != nil {
	// 		c.JSON(http.StatusUnauthorized, gin.H{
	// 			"status": http.StatusUnauthorized,
	// 			"error":  err.Error(),
	// 		})
	// 		c.Abort()
	// 		return
	// 	}
	// 	c.Next()
	// }
	return func(context echo.Context) error {
		return nil
	}
}

func CORSMiddleware() echo.HandlerFunc {
	// return func(c *gin.Context) {
	// 	c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	// 	c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
	// 	c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
	// 	c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, PATCH, DELETE")
	//
	// 	if c.Request.Method == "OPTIONS" {
	// 		c.AbortWithStatus(204)
	// 		return
	// 	}
	// 	c.Next()
	// }
	return func(context echo.Context) error {
		return nil
	}
}

// Avoid a large file from loading into memory
// If the file size is greater than 8MB dont allow it to even load into memory and waste our time.
func MaxSizeAllowed(n int64) echo.HandlerFunc {
	// return func(c *gin.Context) {
	// 	c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, n)
	// 	buff, errRead := c.GetRawData()
	// 	if errRead != nil {
	// 		//c.JSON(http.StatusRequestEntityTooLarge,"too large")
	// 		c.JSON(http.StatusRequestEntityTooLarge, gin.H{
	// 			"status":     http.StatusRequestEntityTooLarge,
	// 			"upload_err": "too large: upload an image less than 8MB",
	// 		})
	// 		c.Abort()
	// 		return
	// 	}
	// 	buf := bytes.NewBuffer(buff)
	// 	c.Request.Body = ioutil.NopCloser(buf)
	// }
	return func(context echo.Context) error {
		return nil
	}
}